package com.sgzn.sgpay.web.controller;

import com.sgzn.sgpay.model.request.SgsUserDiscountRuleQueryRequest;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.model.response.vo.UserDiscountRuleVo;
import com.sgzn.sgpay.service.SgsUserDiscountRuleService;
import com.sgzn.sgpay.web.controller.base.UserBaseController;
import com.sgzn.sgpay.web.handle.AssembleCommonHandle;
import com.sgzn.sgpay.web.request.Impl.UserDiscountRuleQueryRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by linliangfang 13580393408
 * DATETIME:2018/6/17 16:41
 * Description:
 */
@Controller
@Slf4j
@RequestMapping("/user")
public class UserDiscountRuleQueryController extends UserBaseController{

    @Resource
    private SgsUserDiscountRuleService sgsUserDiscountRuleService;
    @Resource
    private AssembleCommonHandle assembleCommonHandle;

    @RequestMapping("/queryDiscountRule")
    @ResponseBody
    public SgsResultResponse<List<UserDiscountRuleVo>> queryDiscountRule(UserDiscountRuleQueryRequest request){
        super.setUserInfo(request);
        return sgsUserDiscountRuleService.queryDiscountRule(assembleRequest(request));
    }

    /**
     * 组装服务请求
     * @param request
     * @return
     */
    private SgsUserDiscountRuleQueryRequest assembleRequest(UserDiscountRuleQueryRequest request) {
        SgsUserDiscountRuleQueryRequest sgsUserDiscountRuleQueryRequest = new SgsUserDiscountRuleQueryRequest();
        assembleCommonHandle.assembleUserRequest(request, sgsUserDiscountRuleQueryRequest);
        return sgsUserDiscountRuleQueryRequest;
    }
}
